package com.lianliankan.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.lianliankan.model.Score;

public class SettlementAsyncTask extends AsyncTask<Object, Object, String> {
	private Score score;
	private String action;

	public SettlementAsyncTask(Score score, String action) {
		this.score = score;
		this.action = action;
	}

	// 异步操作时执行
	@Override
	protected String doInBackground(Object... params) {
		HttpHelper httpHelper = new HttpHelper();
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		if (action == "end") {
			NameValuePair nameValuePair1 = new BasicNameValuePair("playScore",
					String.valueOf(score.getPlayScore()));
			NameValuePair nameValuePair2 = new BasicNameValuePair("money",
					String.valueOf(score.getUser().getMoney()));
			NameValuePair nameValuePair3 = new BasicNameValuePair("experience",
					String.valueOf(score.getUser().getExperience()));
			NameValuePair nameValuePair4 = new BasicNameValuePair("action",
					"end");
			nameValuePairs.add(nameValuePair1);
			nameValuePairs.add(nameValuePair2);
			nameValuePairs.add(nameValuePair3);
			nameValuePairs.add(nameValuePair4);
		} else if (action == "begin") {
			NameValuePair nameValuePair1 = new BasicNameValuePair("action",
					"begin");
			nameValuePairs.add(nameValuePair1);
		}
		httpHelper.httpGetRank(nameValuePairs, "Settlement.aspx");
		return "";
	}

	// 在doInBackground后执行
	@Override
	protected void onPostExecute(String state) {

	}
}